<!doctype html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, maximum-scale = 1, minimum-scale=1" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="viewport" content="target-densitydpi=device-dpi,width=640,user-scalable=0">
		<title>车栈-会员中心</title>
		<link href="css/style.css" rel="stylesheet" type="text/css" />
		<script src="js/jquery-1.8.2.min.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
	</head>

	<body>
		<section class="section">

			<div class="pos-top" style="margin-top: -80px">

				<div class="header" id="account_header">
					<div class="touxiang"><img src="images/touxiang.png" height="100" width="100"></div>
					<div class="account" id="account">未登录账号</div>
					<div class="xiugai"><img src="images/xiugai.png"> </div>
				</div>
				<div class="clear"></div>

				<div class="per">
					<ul>
						<li>
							<div class="icon"><img src="images/wdjf.png"></div>
							<p>我的积分<span id="credit">0积分</span>
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li>
							<div class="icon"><img src="images/wdyy.png"></div>
							<p>我的预约
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li>
							<div class="icon"><img src="images/jyjl.png"></div>
							<p>加油记录
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li>
							<div class="icon"><img src="images/yhjl.png"></div>
							<p>养护记录
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li class="gopage" data-url="order_list.html" data-login="1">
							<div class="icon"><img src="images/wddd.png"></div>
							<p>我的订单
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li class="gopage" data-url="about.html">
							<div class="icon"><img src="images/gywm.png"></div>
							<p>关于我们
								<a><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li>
							<div class="icon"><img src="images/hysj.png"></div>
							<p>会员升级
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
						<li id="checkin">
							<div class="icon"><img src="images/hyqd.png"></div>
							<p>会员签到
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>

						<li id="logout">
							<div class="icon"><img src="images/hyqd.png"></div>
							<p>退出登陸
								<a href=""><img src="images/jiantou.png"></a>
							</p>
						</li>
					</ul>
				</div>
			</div>

			<!--底部导航-->
			<div class="clear"></div>

		</section>
	</body>

</html>
<script>
	mui.init({

	});
	mui.plusReady(function() {
		//如果已经登陆，传入用户名

		getUserInfo();

		//跳转页面。加入了判断登陆得功能
		mui("body").on("tap", ".gopage", function() {

			var this_obj = jQuery(this);
			var url = this_obj.data("url");
			var id = this_obj.data("param");
			var login = this_obj.data("login");
			if(login == 1) {
				//说明必须要验证登录
				var if_login = plus.storage.getItem("if_login");
				if(if_login != 1) {
					url = "login.html";
				}

			}
			//  mui.toast(id);
			mui.openWindow({
				id: url,
				url: url,
				extras: {
					data_id: id,

				},
				waiting: {
					autoShow: false,
				}
			})
		});
		//店頭部
		var account_header = document.getElementById("account_header");

		account_header.addEventListener('tap', function(event) {

			var if_login = plus.storage.getItem("if_login");

			if(if_login != 1) {
				url = "login.html";
			}

			mui.openWindow({
				id: url,
				url: url,
				extras: {

				},
				waiting: {
					autoShow: false,
				}
			})
		}, false);

		var logout = document.getElementById("logout");

		logout.addEventListener('tap', function(event) {

			plus.storage.removeItem("if_login");
			plus.storage.removeItem("name");
			plus.storage.removeItem("password");
			var url = "login.html";
			mui.openWindow({
				id: url,
				url: url,
				extras: {

				},
				waiting: {
					autoShow: false,
				}
			})

		}, false);

	})
	//签到
	var checkin = document.getElementById("checkin");
	checkin.addEventListener('tap', function(event) {
		var if_login = plus.storage.getItem("if_login");
		if(if_login != 1) {
			url = "login.html";
			mui.openWindow({
				id: url,
				url: url,
				extras: {

				},
				waiting: {
					autoShow: false,
				}
			})
		} else {
			var user_id = plus.storage.getItem("user_id");
			var postData = {
				apiUrl: web_url + "index/checkin.shtml",
				datas: {
					user_id: user_id
				}
			};

			app.postServer(postData,
				function(result) {
					mui.toast("签到成功");
			   $("#credit").html(result.credit+"积分");

				},
				function(err) {
					if(err) {
						plus.nativeUI.toast(err);
						return;
					}
				}
			);

		}

	}, false);

	//获取用户个人信息
	function getUserInfo() {

		var uid = plus.storage.getItem("user_id")
		var if_login = plus.storage.getItem("if_login");

		if(if_login == 1) {

			var postData = {
				apiUrl: web_url + "index/getUserInfo.shtml",
				datas: {
					user_id: uid
				}
			};

			app.postServer(postData,
				function(result) {
					$("#account").html(result.user.phone);
					$("#credit").html(result.user.credit + "积分");
					//console.log(result.user.phone);

				},
				function(err) {
					if(err) {
						plus.nativeUI.toast(err);
						return;
					}
				}
			);
		}

	}
</script>